package com.lagou.edu.message.mq.listener;

import com.alibaba.fastjson.JSON;
import com.lagou.edu.common.constant.MQConstant;
import com.lagou.edu.common.mq.RocketMqService;
import com.lagou.edu.common.mq.dto.BaseMqDTO;
import com.lagou.edu.common.mq.listener.AbstractMqListener;
import com.lagou.edu.message.api.dto.CourseStatusReleaseDTO;
import com.lagou.edu.message.api.dto.LessonStatusReleaseDTO;
import com.lagou.edu.message.api.dto.Message;
import com.lagou.edu.message.service.IMessageService;
import io.jsonwebtoken.lang.Collections;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.UUID;

@Slf4j
@Component
@RocketMQMessageListener(topic = MQConstant.Topic.COURSE_STATUS_RELEASE, consumerGroup = "${rocketmq.producer.group}" + "_" + MQConstant.Topic.COURSE_STATUS_RELEASE)
public class CourseStatusReleaseListener extends AbstractMqListener<BaseMqDTO<CourseStatusReleaseDTO>> implements RocketMQListener<BaseMqDTO<CourseStatusReleaseDTO>>{

    @Autowired
    private IMessageService messageService;
    @Autowired
    private RocketMqService rocketMqService;

    @Override
    public void onMessage(BaseMqDTO<CourseStatusReleaseDTO> data) {
        log.info("onMessage - data:{}", JSON.toJSONString(data));

        if(this.checkMessageId(data.getMessageId())){
            return;
        }
        CourseStatusReleaseDTO courseStatusReleaseDTO = data.getData();
        if(courseStatusReleaseDTO==null){
            return;
        }
        Message message = new Message();
        message.setContent(courseStatusReleaseDTO.getCourseName()+"课程新上线，欢迎试学");
        messageService.sendMessage(message);

    }
}